﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartMD.DataModel.Entity;
using SmartMD.DataAccess.Service;
using System.Collections.ObjectModel;
using SmartMD.Manager.Common;
using System.Windows.Controls;

namespace SmartMD.Manager.Utils
{
    public class ComboxUtil
    {
        public static void InitializeComboxByDict(object sender, string dictName)
        {
            DictionaryType dictType = DataServiceManager.DataDictService.loadDictianryByName(dictName);
            if (dictType == null)
                return;
            ObservableCollection<DictionaryItem> dictItemList = dictType.Items;
            List<ComboBoxValueItem> datasource = new List<ComboBoxValueItem>();

            for (int i = 0; i < dictItemList.Count; i++)
            {
                DictionaryItem item = dictItemList[i];
                datasource.Add(new ComboBoxValueItem { Name = item.Name, Value = item.Code,  Id = item.Id});
            }

            (sender as ComboBox).ItemsSource = datasource;  
        }
    }
}
